﻿CREATE FUNCTION [dbo].[fn_TableHasPrimaryKey]
(
	@Table sysname
)
RETURNS BIT
AS
BEGIN
	DECLARE @True  BIT; SET @True  = 1
	DECLARE @False BIT; SET @False = 0
	
	IF EXISTS (
	       SELECT *
	       FROM   sys.tables t
	              INNER JOIN sys.key_constraints kc
	                   ON  t.[object_id] = kc.parent_object_id
	       WHERE  t.[name] = @Table
	              AND t.[type] = 'U'
	              AND kc.[type] = 'PK'
	   )
	    RETURN @True
	
	RETURN @False
END